﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace <%=@ui_namespace%>
{
    public partial class ucListAndEdit_<%= @table.TableName %> : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.pnlRecord.Visible = false;
            }

            this.ucList_<%= @table.TableName %>1.ItemSelected += new <%= @table.TableName %>SelectHandler(ucList_<%= @table.TableName %>1_ItemSelected);
            this.ucList_<%= @table.TableName %>1.NewRecordRequested += new EventHandler(ucList_<%= @table.TableName %>1_NewRecordRequested);
            this.ucEditForm_<%= @table.TableName %>1.RecordClosed += new EventHandler(ucEditForm_<%= @table.TableName %>1_RecordClosed);
            this.ucEditForm_<%= @table.TableName %>1.RecordSaved += new EventHandler(ucEditForm_<%= @table.TableName %>1_RecordSaved);
        }

        void ucEditForm_<%= @table.TableName %>1_RecordSaved(object sender, EventArgs e)
        {
            this.ucList_<%= @table.TableName %>1.LoadList();
        }

        void ucEditForm_<%= @table.TableName %>1_RecordClosed(object sender, EventArgs e)
        {
            this.ucList_<%= @table.TableName %>1.LoadList();
            this.pnlRecord.Visible = false;
        }

        void ucList_<%= @table.TableName %>1_NewRecordRequested(object sender, EventArgs e)
        {
            this.ucEditForm_<%= @table.TableName %>1.NewRecord();
            this.pnlRecord.Visible = true;
        }

        void ucList_<%= @table.TableName %>1_ItemSelected(object sender, <%= @table.TableName %>SelectEventArgs e)
        {
            this.pnlRecord.Visible = true;
            decimal id = e.ID;
            this.ucEditForm_<%= @table.TableName %>1.LoadRecord(id);
        }

    }
}